package com.zzl.alligator.management.system.controller;

import com.zzl.alligator.framework.base.controller.BaseController;
import com.zzl.alligator.framework.support.web.vo.JsonResult;
import com.zzl.alligator.management.system.domain.SysNotice;
import com.zzl.alligator.management.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通知公告表(SysNotice)控制层
 *
 * @author zhouziliang
 * @since 2020-06-30
 */
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {
    
    /**
     * 服务对象
     */
    @Autowired
    private ISysNoticeService sysNoticeService;


    /**
     * 分页查询所有数据
     *
     * @param sysNotice 查询实体
     * @return 所有数据
     */
    @GetMapping
    public JsonResult findList(SysNotice sysNotice) {
        startPage();
        List<SysNotice> sysNoticeList = sysNoticeService.findSysNoticeList(sysNotice);
        return JsonResult.success(getDataTable(sysNoticeList));
    }

    @GetMapping("/person/{id}")
    public JsonResult findPersionList(@PathVariable("id") Long id) {
        startPage();
        List<SysNotice> sysNoticeList = sysNoticeService.findSysNoticeListByUserId(id);
        return JsonResult.success(getDataTable(sysNoticeList));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param noticeId 主键
     * @return 单条数据
     */
    @GetMapping("/{noticeId}")
    public JsonResult findById(@PathVariable Integer noticeId) {
        return JsonResult.success(sysNoticeService.findSysNoticeById(noticeId));
    }

    /**
     * 新增数据
     *
     * @param sysNotice 实体对象
     * @return 新增结果
     */
    @PostMapping
    public JsonResult add(@RequestBody SysNotice sysNotice) {

        return JsonResult.success(this.sysNoticeService.insertSysNotice(sysNotice));
    }

    /**
     * 修改数据
     *
     * @param sysNotice 实体对象
     * @return 修改结果
     */
    @PutMapping
    public JsonResult update(@RequestBody SysNotice sysNotice) {
        return JsonResult.success(this.sysNoticeService.updateSysNotice(sysNotice));
    }


    /**
     * 删除数据
     *
     * @param noticeId 主键
     * @return 删除结果
     */
    @DeleteMapping("/{noticeId}")
    public JsonResult delete(@PathVariable Integer noticeId) {
        return toAjax(this.sysNoticeService.deleteById(noticeId));
    }

    @GetMapping("/pub")
    public JsonResult findPubNotication() {
        this.startPage();
        List<SysNotice> sysNoticeList = sysNoticeService.findPublicNotice();
        return JsonResult.success(getDataTable(sysNoticeList));

    }
}